package com.wwl.io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class PropertiesDemo {
    public static void main(String[] args) {
        //PropertiesDemo.readProperties();
        PropertiesDemo.writeProperties();
    }

    public static void readProperties(){
        try {
            FileReader fr = new FileReader("user.info");
            Properties prop = new Properties();
            prop.load(fr);
            System.out.println("username="+prop.getProperty("username"));
            System.out.println("age="+prop.getProperty("age"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void writeProperties(){
        try {
            Properties prop = new Properties();
            FileWriter fw = new FileWriter("user.info",true);
            prop.setProperty("bookprice","20.50");
            prop.store(fw,"info");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
